package com.link.database.service.impl;

import com.link.database.dao.DBAccountDao;
import com.link.database.entity.DBAccount;
import com.link.database.service.DBAccountService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DBAccountServiceImpl implements DBAccountService {
    
    @Resource
    private DBAccountDao accountDao;
    
    @Override
    public DBAccount selectById(long id) {
        return accountDao.selectById(id);
    }
    
    @Override
    public List<DBAccount> selectAll() {
        return accountDao.selectAll();
    }
    
    @Override
    public DBAccount selectByUsername(String username) {
        return accountDao.selectByUsername(username);
    }
    
    @Override
    public DBAccount selectByUsernameAndPassword(String username, String password) {
        return accountDao.selectByUsernameAndPassword(username, password);
    }
    
    @Override
    public int insert(DBAccount account) {
        return accountDao.insert(account);
    }
    
    @Override
    public int update(DBAccount account) {
        return accountDao.update(account);
    }
    
    @Override
    public int deleteById(long id) {
        return accountDao.deleteById(id);
    }

    @Override
    public int register(DBAccount account) {
        DBAccount existingAccount = accountDao.selectByUsername(account.getUsername());
        if (existingAccount != null) {
            throw new RuntimeException("Username already exists");
        }
        return accountDao.insert(account);
    }
}